home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / c / AmigaDate.lha / amigadate.c < prev    next >
C/C++ Source or Header  |  1994-03-31  |  4KB  |  177 lines

  1. ;/*
  2. ; * $Id: amigadate.c $
  3. ; *
  4. ; * Author: Tomi Ollila <too@cs.hut.fi>
  5. ; *
  6. ; * Created: Wed Mar 30 23:53:45 1994 too
  7. ; * Last modified: Thu Mar 31 16:22:23 1994 too
  8. ; *
  9. ; *
  10. echo gcc -v -O2 -nostdlib -D__AMIGADATE__... + -s -o amigadate amigadate.c
  11. gcc -v -O2 -nostdlib -D__AMIGADATE__="(31.3.94)" -s -o amigadate amigadate.c
  12. quit 0
  13. ; *
  14. ; */
  15.  
  16. #define NULL 0
  17.  
  18. asm(".text; jmp pc@(_start-.+2);");
  19.  
  20. static const char version[] = "$VER: amigadate 1.0 " __AMIGADATE__ "\n";
  21.  
  22. struct Library;
  23.  
  24. typedef unsigned char u_char;
  25. typedef long BPTR;
  26.  
  27. struct dts {
  28.   long        ds_x1;
  29.   long        ds_x2;
  30.   long        ds_x3;
  31.   u_char    dt_Format;
  32.   u_char    dt_Flags;
  33.   char *    dt_x1;
  34.   char *    dt_StrDate;
  35.   char *    dt_x2;
  36. };
  37.  
  38. /**************** Needed Exec library inlines (modified) *******************/
  39.  
  40. static __inline struct Library *
  41. OpenLibrary (struct Library * SysBase, char * libName, unsigned long version)
  42. {
  43.   register struct Library * _res __asm("d0");
  44.   register struct Library *a6 __asm("a6") = SysBase;
  45.   register char *a1 __asm("a1") = libName;
  46.   register unsigned long d0 __asm("d0") = version;
  47.   __asm __volatile ("jsr a6@(-0x228)"
  48.   : "=r" (_res)
  49.   : "r" (a6), "r" (a1), "r" (d0)
  50.   : "a0","a1","d0","d1", "memory");
  51.   return _res;
  52. }
  53. static __inline void
  54. CloseLibrary (struct Library * SysBase, struct Library * library)
  55. {
  56.   register struct Library *a6 __asm("a6") = SysBase;
  57.   register struct Library *a1 __asm("a1") = library;
  58.   __asm __volatile ("jsr a6@(-0x19e)"
  59.   : /* no output */
  60.   : "r" (a6), "r" (a1)
  61.   : "a0","a1","d0","d1", "memory");
  62. }
  63.  
  64. /**************** Needed DOS library inlines (modified) ********************/
  65.  
  66. static __inline struct dts *
  67. DateStamp (struct Library * DOSBase, struct dts * date)
  68. {
  69.   register struct dts * _res  __asm("d0");
  70.   register struct Library *a6 __asm("a6") = DOSBase;
  71.   register struct dts *d1 __asm("d1") = date;
  72.   __asm __volatile ("jsr a6@(-0xc0)"
  73.   : "=r" (_res)
  74.   : "r" (a6), "r" (d1)
  75.   : "a0","a1","d0","d1", "memory");
  76.   return _res;
  77. }
  78. static __inline long
  79. DateToStr (struct Library * DOSBase, struct dts *datetime)
  80. {
  81.   register long  _res  __asm("d0");
  82.   register struct Library *a6 __asm("a6") = DOSBase;
  83.   register struct dts *d1 __asm("d1") = datetime;
  84.   __asm __volatile ("jsr a6@(-0x2e8)"
  85.   : "=r" (_res)
  86.   : "r" (a6), "r" (d1)
  87.   : "a0","a1","d0","d1", "memory");
  88.   return _res;
  89. }
  90. static __inline long
  91. Write (struct Library * DOSBase, BPTR file, char * buffer, long length)
  92. {
  93.   register long  _res  __asm("d0");
  94.   register struct Library *a6 __asm("a6") = DOSBase;
  95.   register BPTR d1 __asm("d1") = file;
  96.   register char * d2 __asm("d2") = buffer;
  97.   register long d3 __asm("d3") = length;
  98.   __asm __volatile ("jsr a6@(-0x30)"
  99.   : "=r" (_res)
  100.   : "r" (a6), "r" (d1), "r" (d2), "r" (d3)
  101.   : "a0","a1","d0","d1","d2","d3", "memory");
  102.   return _res;
  103. }
  104. static __inline BPTR
  105. Output (struct Library * DOSBase)
  106. {
  107.   register BPTR  _res  __asm("d0");
  108.   register struct Library *a6 __asm("a6") = DOSBase;
  109.   __asm __volatile ("jsr a6@(-0x3c)"
  110.   : "=r" (_res)
  111.   : "r" (a6)
  112.   : "a0","a1","d0","d1", "memory");
  113.   return _res;
  114. }
  115.  
  116. /*************************************************************************/
  117.  
  118. int start()
  119. {
  120.   struct Library * SysBase;
  121.   struct Library * DOSBase;
  122.   struct dts date;
  123.   char buf[17];
  124.   int i;
  125.  
  126.   date.dt_x1 = date.dt_x2 = 0;
  127.   date.dt_Flags = 0;
  128.   date.dt_StrDate = buf + 1;
  129.   date.dt_Format = 3;
  130.  
  131.   SysBase = *(struct Library **)4;
  132.  
  133.   if ((DOSBase = OpenLibrary(SysBase, "dos.library", 36)) == NULL)
  134.     return 20;
  135.  
  136.   DateStamp(DOSBase, &date);
  137.   DateToStr(DOSBase, &date);
  138.  
  139.   /* buf = " dd-mm-yy "
  140.         0123456789 */
  141.  
  142.   buf[6] = '.';                 /* " xd-xm.yy" */
  143.   buf[9] = ')';                 /* " xd-xm.yy)" */
  144.   buf[10] = '\n';
  145.  
  146.   if (buf[4] == '0') {          /* " xd-0m.yy)" */
  147.     i = 1;
  148.     buf[4] = '.';               /* " xd-.m.yy)" */
  149.     buf[3] = buf[2];        /* " xxd.m.yy)" */
  150.     if (buf[1] == '0') {        /* " 0xd.m.yy)" */
  151.       i = 2;
  152.       buf[2] = '(';             /* "  (d.m.yy)" ***/
  153.     }
  154.     else {
  155.       buf[2] = buf[1];        /* "  dd.m.yy)" */
  156.       buf[1] = '(';             /* " (dd.m.yy)" ***/
  157.     }
  158.   }
  159.   else {
  160.     buf[3] = '.';               /* " xd.mm.yy)" */
  161.     if (buf[1] == '0') {        /* " 0d.mm.yy)" */
  162.       i = 1;
  163.       buf[1] = '(';             /* " (d.mm.yy)" ***/
  164.     }
  165.     else {
  166.       i = 0;
  167.       buf[0] = '(';             /* "(dd.mm.yy)" ***/
  168.     }
  169.   }
  170.  
  171.   Write(DOSBase, Output(DOSBase), buf + i, 11 - i);
  172.  
  173.   CloseLibrary(SysBase, DOSBase);
  174.  
  175.   return 0;
  176. }
  177.